package com.cos.lession76sb2.config;

import com.cos.lession76sb2.web.inteceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;

/**
 * @author: COS
 * @time: 2022/10/9 16:01
 * @description:
 */
@Configuration
public class MyWebMvcConfiguration implements WebMvcConfigurer {
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/10/9 16:04
     * @description:
     * 配置视图解析器
     */
    @Bean
    public InternalResourceViewResolver getInternalResourceViewResolver(){
        InternalResourceViewResolver i = new InternalResourceViewResolver( );
        i.setPrefix("/");
        i.setSuffix(".jsp");
        return i;
    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/10/9 16:43
     * @description: 配置静态资源的映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/xxxx/**").addResourceLocations("/aaaa/");
//        registry.addResourceHandler("/xxxx/**").addResourceLocations("/aaaa/");
//        registry.addResourceHandler("/xxxx/**").addResourceLocations("/aaaa/");
    }

    //1 注入自定义拦截器类
    @Autowired
    private MyInterceptor my;

    /**
     * 配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(my).addPathPatterns("/**").excludePathPatterns("/sys/**");
//        registry.addInterceptor(my).addPathPatterns("/**").excludePathPatterns("/sys/**");
    }


}
